#include "state.h"
#include "conversion.h"

#include <iostream>
#include <fstream>
#include <cstdlib>
#include <iomanip>

using namespace std;

double findFidelity(int length, double eps);

int main(int argc, char** argv)
{
    Process process(argc, argv);


    for (int n = 15; n < 16; n++) {
        for (int i = 0; i < 5; i++) {
            double res = 1 - findFidelity(n,0.01);
            if (process.getRank() == 0)
                cout << fixed << setprecision(20) << res << endl;
        }
    }
    complexd h[] = {
        complexd(1/sqrt(2), 0), complexd( 1/sqrt(2), 0),
        complexd(1/sqrt(2), 0), complexd(-1/sqrt(2), 0)
    };
    Conversion H(4,h);

    State state(16);
    state.nConversion(H, 0.01);



    return 0;
}


double findFidelity(int n, double eps)
{
    complexd h[] = {
        complexd(1/sqrt(2), 0), complexd( 1/sqrt(2), 0),
        complexd(1/sqrt(2), 0), complexd(-1/sqrt(2), 0)
    };
    Conversion H(4,h);

    State state_noize(n), state_ideal(n);

    state_ideal.randomFill();
    state_ideal.norma();
    state_noize = state_ideal;
    state_ideal.n0Conversion(H);
    state_noize.nConversion(H,eps);
    double F = abs(state_noize * state_ideal);
    F = F * F;

    return F;
}
